#include "omp.h"
#include <iostream>
#include <vector>

using namespace std;

int main() {
    int thread_num = omp_get_num_procs();
    vector<int> A(thread_num);
    vector<int> B(thread_num);
    vector<int> C(thread_num);

    for (int i = 0; i < thread_num; i++) {
        A[i] = 0;
        B[i] = i;
        C[i] = i;
    }
    int id = 0;
#pragma omp parallel shared(A, B, C) private(id)
    {
        id = omp_get_thread_num();
        A[id] = id;
        //每一个线程都需要等待知道所有的线程都到达, 就是默认情况
#pragma omp barrier
#pragma omp for
        for (int i = 0; i < thread_num; i++) {
            C[i] = i + A[i];
        }
        //只要不是主线程, 就直接结束, 不等待
#pragma omp for nowait
        for (int i = 0; i < thread_num; i++) {
            B[i] = C[i] + i;
        }
        A[id] = id + 1;
    }
    for (int i = 0; i < thread_num; i++) {
        printf("%d ", A[i]);
    }
    printf("\n");
    for (int i = 0; i < thread_num; i++) {
        printf("%d ", B[i]);
    }
    printf("\n");
    for (int i = 0; i < thread_num; i++) {
        printf("%d ", C[i]);
    }
    printf("\n");
    return 0;
}